import Vue from 'vue';
import './style.scss';
import tpl from './tpl.html';
import modal from '../../../../../grsc-base/component/Modal.vue';
import help from '../../../../../grsc-base/component/Help.vue';
import Popover from '../../../../../grsc-base/component/Popover.vue';
import service from '../../basic/service';
import Validator from '../../../../../grsc-base/component/Validator/main';
export default Vue.extend({
  template: tpl,
  components: {
    modal,
    Popover,
    help,
    Validator
  },
  props: ['name', 'list', 'bingding'],
  data() {
    return {
      loading: '',
      form: {
        weChatNo: '',
        type: this.name,
      },
      rules: {
        weChatNo: {
          required: true,
          requiredTip: this.$t('basic.setWeChat.tip')
        }
      },
    }
  },
  created() {},
  methods: {
    //发起绑定
    submit() {
      if (this.rules.$checkAll() === false) {
        return;
      }
      service.bindingWechat({
        weChat: this.form.weChatNo,
        type: this.bingding ? 'update' : 'binding',
        accountType: this.form.type
      }).done(data => {
        if (data.code == '100200') {
          this.hide(this.form.weChatNo)
          window.success(data.msg)
        } else {
          window.error(data.msg)
        }
      })
    },
    //隐藏弹窗
    hide(data) {
      this.$emit('hide', data);
      this.form.weChatNo = '';
    }
  }
})